﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.IotInfo;
using LJX.SmartPark.Domain.Student;
using LJX.SmartPark.Service.IotInfo.Dto;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Service.IotInfo
{
    public class TricolourLightLogServeice : ITricolourLightLogServeice
    {
        private readonly IRepository<TricolourLightLog> _studentService;

        public TricolourLightLogServeice(IRepository<TricolourLightLog> studentService)
        {
            _studentService = studentService;
        }

        public async Task<Response<bool>> DeleteByIdAsync(TricolourLightLog input)
        {
            var result = await _studentService.DeleteByIdAsync(input.MapTo<TricolourLightLog>());
            return Response<bool>.Ok(result > 0);
        }

        /// <summary>
        /// 获取总条数
        /// </summary>
        /// <returns></returns>
        public int GetCount()
        {
            return _studentService.GetCount();
        }

        /// <summary>
        /// 显示分页查询
        /// </summary>
        /// <param name="fenye"></param>
        /// <returns></returns>
        public async Task<Response<List<TricolourLightLog>>> GetTricolourLightLogAsync(SelectRizhi select)
        {
            var students = await _studentService.GetAllListAsync();

            var result = students.MapToList<TricolourLightLog>();


            if (!string.IsNullOrWhiteSpace(select.equipMentNum))
            {
                result = result.Where(x => x.EquipMentNum.Contains(select.equipMentNum)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(select.connectionStatus))
            {
                result = result.Where(a => a.ConnectionStatus == bool.Parse(select.connectionStatus)).ToList();
            }

            var totalCount = result.Count();

            result = result.Skip(((select.pageIndex - 1) * select.pageSize)).Take(select.pageSize).ToList();

            return Response<List<TricolourLightLog>>.Ok(result, totalCount);
        }

    }
    /// <summary>
    /// 三色灯日志查询
    /// </summary>
    public class SelectRizhi
    {
        public int pageIndex { get; set; }
        public int pageSize { get; set; }
        public string? connectionStatus { get; set; }
        public string? equipMentNum { get; set; }
    }
}
